package com.gxuwz.eschool.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.fragment.app.Fragment;

import com.gxuwz.eschool.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class PersonFragment extends Fragment implements AdapterView.OnItemClickListener{
    ListView listView;
    SimpleAdapter simpleAdapter;
     public PersonFragment() {

    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

      }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view =inflater.inflate(
                R.layout.fragment_person,container,false
        );
        listView =view.findViewById(R.id.person_menu_list);

        simpleAdapter = new SimpleAdapter(
                getActivity(),
                getData(),
                R.layout.person_menu_item,
                new String[]{"menuName","pic"},
                new int[]{R.id.person_menu_name,R.id.person_menu_pic}
        );
        listView.setAdapter(simpleAdapter);

        listView.setOnItemClickListener(this);
        return view;


//        return inflater.inflate(R.layout.fragment_person, container, false);
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        System.out.println("position:"+position);
        String text = listView.getAdapter().getItem(position).toString();
        System.out.println("position:"+position+"text"+text);
    }


    private List<Map<String,Object>> getData() {
        String [] titles={"交易记录","话费充值","常见问题","投诉建议","系统设置"};
        int [] images={R.drawable.jiaoyijilu, R.drawable.huafeichongzhi, R.drawable.changjianwenti, R.drawable.tousujianyi,R.drawable.xitongshezhi};
        List<Map<String,Object>> list= new ArrayList<>();
        for(int i=0;i<5;i++){
            Map  map = new HashMap();
            map.put("menuName",titles[i]);
            map.put("pic",images[i]);
            list.add(map);
        }
        return list;
    }




}